﻿using System;
using System.Collections.Generic;
using EnvDTE;
using EnvDTE80;


namespace VsTortoiseSVN.Commands
{
    public class SolutionExplorerSelectedItemsLock : SolutionExplorerSelectedItemsBase
    {
        public SolutionExplorerSelectedItemsLock(DTE2 application, string name, string caption, string tooltip, int bitmapId)
            : base(application, name, caption, tooltip, bitmapId)
        {
        }

        protected override vsCommandStatus QueryContextSensitiveStatus()
        {
            List<string> fullNames = GetFullNames();
            foreach (string fullName in fullNames)
            {
                if (SvnHelper.IsVersionControlled(fullName) && !SvnHelper.IsLockedLocally(fullName))
                    return vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
            }

            return vsCommandStatus.vsCommandStatusUnsupported;
        }

        public override bool Exec()
        {
            List<string> fullNames = GetFullNames();
            TortoiseProc.Instance.Lock(fullNames);
            return true;
        }
    }
}
